package com.wanmait.houlang.manageController;

import com.github.pagehelper.PageInfo;
import com.wanmait.houlang.pojo.DTO;
import com.wanmait.houlang.pojo.Manager;
import com.wanmait.houlang.service.ManagerService;
import com.wanmait.houlang.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/manage")
public class ManagerController {
    @Resource
    private ManagerService managerService;

    //获取所有的管理员
    @PostMapping("managers/{pageNum:\\d+}")
    public Result allManager(@PathVariable Integer pageNum, @RequestBody DTO dto){
        int pageSize=5;
        PageInfo<Manager> managerPageInfo = managerService.findAll(pageNum, pageSize, dto);
        return Result.success(managerPageInfo);
    }
    //添加管理员
    @PostMapping("addManager")
    public Result addManager(@RequestBody Manager manager){
        managerService.insert(manager);
        return Result.success("添加成功");
    }
    //修改管理员信息
    @PostMapping("updateManager")
    public Result updateManagerInfo(@RequestBody Manager manager){
        System.out.println(manager.getTel());
        managerService.updateManagerInfo(manager);
        return Result.success("修改成功");
    }
    //修改管理员的状态
    @GetMapping("updateStatus/{id:\\d+}")
    public Result updateStatus(@PathVariable("id") Integer managerId){
        managerService.updateStatus(managerId);
        return Result.success();
    }
}
